package com.gopay.webtest.controller.cloud;


import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import com.gopay.webtest.vo.cloud.Cloud0619Vo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.controller.base.BaseController;
import com.gopay.webtest.handler.cloud.TransCloudSignHandler;
import com.gopay.webtest.util.DateUtils;
import com.gopay.webtest.vo.cloud.Cloud0605Vo;
import com.gopay.webtest.vo.cloud.Cloud0606Vo;
import com.gopay.webtest.xml.XmlDao;

/**
 * 
 * boai
 * 2015年12月26日 
 * www.gopay.com.cn Inc.All rights reserved.
 */
@RequestMapping("/cloudUser")
@Controller
public class CloudUserController extends BaseController{
	
	@Resource(name = "xmlDao")
    private XmlDao xmlDao;
	
	@Resource(name = "transCloudSignHandler")
	private TransCloudSignHandler transCloudSignHandler;
    /**
     * 跳转到申请页面 开户
     * 
     * @return
     */
    @RequestMapping("/chargeApply")
    public ModelAndView chargeApply() {
        ModelAndView mv = new ModelAndView();

        
        try {
        	 Map<String, String> map = xmlDao.readData4Map("cloud_apply", "register");

             map.put("reqTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             mv = new ModelAndView("cloud.charge.register");
             mv.addObject("config", map);
             this.logger.info("^^^^^^^^^^^^^^^^^云平台开户页面初始化成功^^^^^^^^^^^^^^^^^");
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }
    @RequestMapping("/doCharge")
    public ModelAndView doCharge(@ModelAttribute Cloud0605Vo c0605Vo){
    	 ModelAndView mv = new ModelAndView();
         mv.setViewName("cloud.charge.doRegister");

         try {
             // 签名
        	 transCloudSignHandler.sign(c0605Vo.getTranCode()+"_"+c0605Vo.getVersion(), "signType", "signValue", c0605Vo, getRequest());
        	 this.logger.info("^^^^^^^^^^^^^^^^^云平台开户页面签名成功^^^^^^^^^^^^^^^^^");

             mv.addObject("c0605Vo", c0605Vo);
         } catch (Exception e) {
             logger.error("执行申请", e);
         }
         return mv;
    }
    /**
     * 跳转到申请页面 修改
     * 
     * @return
     */
    @RequestMapping("/chargeApplyUp")
    public ModelAndView chargeApplyUp() {
        ModelAndView mv = new ModelAndView();        
        try {
        	 Map<String, String> map = xmlDao.readData4Map("cloud_apply", "update");

             map.put("reqTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             mv = new ModelAndView("cloud.charge.update");
             mv.addObject("config", map);
             this.logger.error("^^^^^^^^^^^^^^^^^云平台修改页面初始化成功^^^^^^^^^^^^^^^^^");
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }   
    @RequestMapping("/doChargeUp")
    public ModelAndView doChargeUp(@ModelAttribute Cloud0606Vo c0606Vo){
    	 ModelAndView mv = new ModelAndView();
        mv.setViewName("cloud.charge.doUpdate");

         try {
             // 签名
        	 transCloudSignHandler.sign(c0606Vo.getTranCode()+"_"+c0606Vo.getVersion(), "signType", "signValue", c0606Vo, getRequest());
        	 this.logger.error("^^^^^^^^^^^^^^^^^云平台修改页面签名成功^^^^^^^^^^^^^^^^^");

             mv.addObject("c0606Vo", c0606Vo);
         } catch (Exception e) {
             logger.error("执行申请", e);
         }
         return mv;
    }    
    
    @RequestMapping("/cloudPage")
    public ModelAndView cloudPage() {
    	ModelAndView mv = new ModelAndView();
    	mv.setViewName("cloud.menu.page");
    	return mv;
    }
    
    @RequestMapping("/cancleCloudPage")
    public ModelAndView cancleCloudPage() {
    	ModelAndView mv = new ModelAndView();
    	mv.setViewName("gopay.webtest.def");
    	return mv;
    }

    @RequestMapping("/backgroundRegisterApply")
    public ModelAndView backgroundRegisterApply() {
        ModelAndView mv = new ModelAndView();


        try {
            Map<String, String> map = xmlDao.readData4Map("cloud_apply", "backgroundRegister");

            map.put("reqTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
            map.put("merOrderNum", System.currentTimeMillis()+"");
            mv = new ModelAndView("cloud.charge.backgroundRegister");
            mv.addObject("config", map);
            this.logger.info("^^^^^^^^^^^^^^^^^云平台后台开户页面初始化成功^^^^^^^^^^^^^^^^^");
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }
    @RequestMapping("/doBackgroundRegister")
    public ModelAndView doBackgroundRegister(@ModelAttribute Cloud0619Vo cloud0619Vo) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("cloud.charge.doBackgroundRegister");

        try {
            // 签名
            transCloudSignHandler.sign(cloud0619Vo.getTranCode()+"_"+cloud0619Vo.getVersion(), "signType", "signValue", cloud0619Vo, getRequest());
            this.logger.info("^^^^^^^^^^^^^^^^^云平台后台开户页面签名成功^^^^^^^^^^^^^^^^^");

            mv.addObject("cloud0619Vo", cloud0619Vo);
        } catch (Exception e) {
            logger.error("执行申请", e);
        }
        return mv;
    }
}
